/*
 * scull.h  -- defintions scull0 - scull3 char module 
 * writed by wangxinyong, 2013/10/12 
 * email: wxy8402@163.com.
 *
 */

#ifndef _SCULL_H_
#define _SCULL_H_

/*
 *Macros to help debugging
 */

#undef PDEBUG 
#ifdef PDEBUG
#ifdef __KERNEL__
#define  PDEBUG(fmt, args...) printk( KERN_DEBUG "scull: " fmt, ## args)
#else
#define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
#endif
#else  /* not define PDEBUG */
#define PDEBUG(fmt, args...)  /* not debugging: nothing */
#endif

#ifndef SCULL_MAJOR
#define SCULL_MAJOR 0   /* dynamic major by default */
#endif

#ifndef SCULL_NR_DEVS
#define SCULL_NR_DEVS 4    /* scull0 through scull3 */
#endif

#ifndef SCULL_QUANTUM
#define SCULL_QUANTUM 4000
#endif

#ifndef SCULL_QSET
#define SCULL_QSET    1000
#endif

#define TYPE(minor)	(((minor) >> 4) & 0xf)	/* high nibble */
#define NUM(minor)	((minor) & 0xf)		/* low  nibble */

struct scull_qset {
	void **data;
	struct scull_qset *next;
};

struct scull_dev {
	struct scull_qset *data;  /* Pointer to first quantum set */
	int quantum;              /* the current quantum size */
	int qset;                 /* the current array size */
	unsigned long size;       /* amount of data stored here */
	struct semaphore sem;
	struct cdev cdev;	  /* Char device structure		*/
};

int scull_trim(struct scull_dev *dev);
int scull_open(struct inode *inode, struct file *filp);
int scull_release(struct inode *inode, struct file *filp);
ssize_t scull_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos);
ssize_t scull_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos);

#endif /* _SCULL_H_ */
